/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.dwusoft.portal.send.method  
 */
package com.dwusoft.platform.template.method;

import java.math.BigDecimal;
import java.util.List;

import com.apache.uct.common.ToolsUtil;

import freemarker.template.TemplateMethodModel;
import freemarker.template.TemplateModelException;

/**
 * description:  
 */
public class FormatPriceMethod implements TemplateMethodModel {

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see freemarker.template.TemplateMethodModel#exec(java.util.List)  
	 */
	public Object exec(List arguments) throws TemplateModelException {
		if (!ToolsUtil.isEmpty(arguments) && arguments.size() > 1) {
			Long price = Long.valueOf(arguments.get(0).toString());
			int num = Integer.valueOf(arguments.get(1).toString());
			double f = price / num;
			BigDecimal b = new BigDecimal(f);
			double f1 = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
			return f1;
		}
		return "";
	}

}
